package com.car.advertising.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.car.advertising.CarApplication;
import com.car.advertising.R;
import com.car.advertising.activity.adapter.IncomeDetailsAdapter;
import com.car.advertising.connection.HttpUrl;
import com.car.advertising.entity.IncomeEntity;
import com.car.advertising.entity.IncomeEntity.SignList;
import com.car.advertising.view.RiseNumberTextView;
import com.support.widget.JumpManager;
import com.support.widget.layout.BaseScrollviewFreshActivity;
import com.support.widget.network.OkHttpClientManager;
import com.support.widget.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

public class IncomeDetailsActivity extends BaseScrollviewFreshActivity {

    private RiseNumberTextView amountTv;
    private TextView balanceTv;
    private TextView presentTv;
    private TextView unlaimedTv;
    private RecyclerView detailsRlv;

    private List<IncomeEntity.SignList> signLists = new ArrayList<>();
    private IncomeDetailsAdapter detailsAdapter;

    @Override
    protected void initToolBar() {
        setTitleClickable(false);
        setSubtitleClickable(true);
        setToolBarBackgroundColor(R.color.color_white);
        setToolBarTitle("收益明细");
        setToolBarTitleColor(R.color.black_bg);

    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_income_details);

        amountTv = (RiseNumberTextView) findViewById(R.id.income_balance_amount_rntv);
        balanceTv = (TextView) findViewById(R.id.income_balance_tv);
        presentTv = (TextView) findViewById(R.id.income_already_present_tv);
        unlaimedTv = (TextView) findViewById(R.id.income_unclaimed_tv);
        detailsRlv = (RecyclerView) findViewById(R.id.income_details_rlv);
        IncomeEntity incomeEntity = getIncomeBean();
        setTextAmount(incomeEntity);
    }

    private IncomeEntity getIncomeBean() {
        List<SignList> signList = new ArrayList<>();
        signList.add(new IncomeEntity().new SignList("钱包生活1", "1", "2017-05-03", "10"));
        signList.add(new IncomeEntity().new SignList("钱包生活2222", "2", "2017-05-03", "10"));
        signList.add(new IncomeEntity().new SignList("钱包生活3333333", "3", "2017-05-03", "10"));
        signList.add(new IncomeEntity().new SignList("钱包生活44444", "4", "2017-05-03", "10"));
        return new IncomeEntity("108", "112", "130", signList);
    }

    private void setTextAmount(IncomeEntity incomeEntity) {
        amountTv.setText(incomeEntity.getBalance());
        balanceTv.setText(incomeEntity.getDrawAmt());
        presentTv.setText(incomeEntity.getDrawAmt());
        unlaimedTv.setText(incomeEntity.getProfit());
        signLists = incomeEntity.getSignList();
        setIncomeAdapter();
    }

    private void setIncomeAdapter() {
        if (detailsAdapter == null) {
            detailsAdapter = new IncomeDetailsAdapter(this, signLists);
            detailsRlv.setLayoutManager(new LinearLayoutManager(this));
            detailsRlv.setAdapter(detailsAdapter);
        } else {
            detailsAdapter.setRefreshList(signLists);
        }
    }

    private void getDetailsData() {
        List<OkHttpClientManager.Param> params = new ArrayList<>();
        params.add(new OkHttpClientManager.Param("acToken", CarApplication.token));
        params.add(new OkHttpClientManager.Param("lastSignId", "T2_80_LqrB6XXYFDMbkqhX"));
        params.add(new OkHttpClientManager.Param("limit", "20"));
        OkHttpClientManager.postAsyn(HttpUrl.getInstance().URL_038, new OkHttpClientManager.ResultCallback<IncomeEntity>() {
            @Override
            public void onError(String request) {
                if (TextUtils.equals(request, "登录已过期")) {
                    JumpManager.gotoActivity(IncomeDetailsActivity.this, LoginActivity.class, false);
                    finish();
                }
            }

            @Override
            public void onResponse(IncomeEntity resp) {
                setTextAmount(resp);
                LogUtil.i(resp);
            }

            @Override
            public void onFinish() {
            }
        }, params, null);
    }

    @Override
    public String getCN() {
        return null;
    }

    @Override
    protected void onRefreshFinish() {

    }

    @Override
    protected void onLoadMoreFinish() {

    }

    @Override
    public void LogoutCallback(boolean islogin) {

    }

    @Override
    public void onCritClick(View v) {

    }

    @Override
    protected boolean isClickable() {
        return false;
    }

    @Override
    protected void subtitleClick() {

    }

    @Override
    protected void titleClick() {

    }

    @Override
    protected void rightClick() {

    }


}
